package com.info.widgets;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionHelper
{
	private String url;
	private static ConnectionHelper instance;

	private ConnectionHelper()
	{
		try {
			//System.out.println("******************************************************************************");
			//Class.forName("com.mysql.jdbc.Driver");
			//url = "jdbc:mysql://localhost:3306/citsdb";
			
			
			System.out.println("Listing all table name in Database!");
			 

				Class.forName("com.mysql.jdbc.Driver");
				url = "jdbc:mysql://localhost:3306/mycaspian";
			  
			  
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() throws SQLException {
		if (instance == null) {
			instance = new ConnectionHelper();
		}
		try {
			return DriverManager.getConnection(instance.url, "root", "admin");
		} catch (SQLException e) {
			throw e;
		}
	}
	
	public static void close(Connection connection)
	{
		try {
			if (connection != null) {
				connection.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}